草庐IT

TypeScript 条件语句

全部标签

javascript - 条件或针对许多字符串的更短语法

我有这样的东西:if(this.selectedItem.label=="str1"||this.selectedItem.label=="str2"||this.selectedItem.label=="str3"||this.selectedItem.label=="str4"){}我想知道是否存在更短的语法来仅使用“this.selectedItem.label”。 最佳答案 可以是数组和indexOf功能?if(["str1","str2","str3","str4"].indexOf(this.selectedItem.l

javascript - 如何使用循环和控制语句在 Javascript 中进行高级字符串模板化

基本上在运行时我得到如下数组varcolors=['red','green','blue'];我需要像下面这样构建一个JSON字符串{"color":{"name":"foo","properties":{...}},"green":{"name":"foo","properties":{...}},"blue":{"name":"foo","properties":{...}}}是否有支持循环和控制语句来构建上述JSON字符串的字符串模板框架 最佳答案 Fit.UIs模板引擎简单直观:http://fitui.org/Core-T

javascript - 为什么新行上的 return 语句不返回任何值?

这个问题在这里已经有了答案:Javascriptfunctionfailstoreturnobjectwhenthereisaline-breakbetweenthereturnstatementandtheobject?(2个答案)关闭4年前。考虑以下情况:functionfunc1(){return{hello:"world"};}functionfunc2(){return{hello:"world"};}console.log(func1());console.log(func2());第一个函数func1()将返回对象{hello:"world"}但第二个函数func2()将

javascript - Javascript 中的这个 if 条件有什么问题?

这个IF条件有什么问题?当我将EEID值设为123456时,它不应出现这种情况。但我看到它来了。有人可以让我知道我做错了什么吗?if((EEID.value.length!=6)||(EEID.value.length!=11)){alert(EEID.value.length);//Thisshowsthatthevaluelength=6alert("YourMemberIDmustbea6digitor11digitnumber.");EEID.focus();returnfalse;} 最佳答案 满足条件是因为EEID.va

javascript - 我想模仿 javascript 正则表达式中的条件

这就是我目前所拥有的...varregex_string="s(at)?u(?(1)r|n)day"console.log("Before:"+regex_string)varregex_string=regex_string.replace(/\(\?\((\d)\)(.+?\|)(.+?)\)/g,'((?!\\$1)$2\\$1$3)')console.log("After:"+regex_string)varrex=newRegExp(regex_string)vararr="thursdaytuesdaythuesdaytursdaysaturdaysundaysurdays

javascript - 替代 OR 语句

我想做的是根据国家代码和下面的脚本重定向国家。下面的代码不起作用。做一些研究我发现我必须使用or语句或者至少那是我认为我需要的,但我的问题是有没有比or语句更简单的方法?如您所见,我正在检查很多国家/地区。varcountry=geoip_country_code();if(country="UK","CA","DE","DK","FR","AU","SE","CH","NL","IT","BE","AT","ES","NO","IE","FI","GB","US"){window.location.href='http://www.google.com';}else{window.l

javascript - 使用 Typescript 中的 Javascript 函数

我正在尝试使用HTML前端构建一个不错的WindowsPhone应用程序。我想使用TYPESCRIPT对我的html页面进行处理。有一个javascript函数对我的应用程序的工作至关重要-window.external.notify我假设这个方法直到运行时才被创建,所以我构建了一个javascript包装函数来确定它在被调用时是否存在。if(window.external.notify!=undefined)window.external.notify(msg);问题是我需要获取我的Typescript文件才能看到此功能。我正在使用VisualStudio2012并且我已经看到帖子-

javascript - typescript + RequireJs + AngularJs

在我的前端,我想将typescript与requireJs和AngularJs一起使用我的typescript可以与angularjs一起使用,但是当我想添加requireJs时,一切都不再起作用了。我希望有人能在这里帮助我:)这基本上是我的结构:在我的索引文件中,我将主文件作为我的requireJs起点这是我的main.ts///require.config({baseUrl:'/js/',paths:{angular:'/components/angular/angular',angularRoute:'/components/angular-route/angular-route

javascript - json 格式的 jison 开始条件

尽管在文档和论坛中进行了长时间的搜索,我仍然无法在node.js中使用JSON格式获得Jison开始条件的正确语法>**Documentationathttp://zaach.github.io/jison/docs/says:>//UsingtheJSONformat,startconditionsaredefinedwithanarray>//beforetherule’s>matcher{rules:[>[['expect'],'[0-9]+"."[0-9]+','console.log("foundafloat,="+yytext);'>]]}但不幸的是,没有人不提供完整的工作

javascript - 无法启动 typescript 编译文件

我已经使用PhantomJs将大型JS项目转换为typescript(作为我的C#程序员)。问题是解释器(phantomjs)在执行此js文件时失败。D:\My\phantomjs-1.9.7-windows\phantomjs.exe--load-images=false--ssl-protocol=any--web-security=no--cookies-file=cookiesC:\Users\alex\Projects\robot\bo.jsTypeError:'undefined'isnotanobject(evaluating'b.prototype')代码是:var__